home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / dos / write.c < prev   
C/C++ Source or Header  |  1996-09-13  |  3KB  |  104 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: write.c,v 1.4 1996/09/13 17:40:35 digulla Exp $
  4.     $Log: write.c,v $
  5.     Revision 1.4  1996/09/13 17:40:35  digulla
  6.     Use IPTR
  7.  
  8.     Revision 1.3  1996/08/13 13:52:53  digulla
  9.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  10.     Replaced __AROS_LA by __AROS_LHA
  11.  
  12.     Revision 1.2  1996/08/01 17:40:59  digulla
  13.     Added standard header for all files
  14.  
  15.     Desc:
  16.     Lang: english
  17. */
  18. #include <clib/exec_protos.h>
  19. #include <dos/filesystem.h>
  20. #include "dos_intern.h"
  21.  
  22. /*****************************************************************************
  23.  
  24.     NAME */
  25.     #include <clib/dos_protos.h>
  26.  
  27.     __AROS_LH3(LONG, Write,
  28.  
  29. /*  SYNOPSIS */
  30.     __AROS_LHA(BPTR, file,   D1),
  31.     __AROS_LHA(APTR, buffer, D2),
  32.     __AROS_LHA(LONG, length, D3),
  33.  
  34. /*  LOCATION */
  35.     struct DosLibrary *, DOSBase, 8, Dos)
  36.  
  37. /*  FUNCTION
  38.     Write some data to a given file. The request is directly
  39.     given to the filesystem - no buffering is involved. For
  40.     small amounts of data it's probably better to use the
  41.     buffered I/O routines.
  42.  
  43.     INPUTS
  44.     file   - filehandle
  45.     buffer - pointer to data buffer
  46.     length - number of bytes to write. The filesystem is
  47.          advised to try to fulfill the request as good
  48.          as possible.
  49.  
  50.     RESULT
  51.     The number of bytes actually written, -1 if an error happened.
  52.     IoErr() will give additional information in that case.
  53.  
  54.     NOTES
  55.  
  56.     EXAMPLE
  57.  
  58.     BUGS
  59.  
  60.     SEE ALSO
  61.  
  62.     INTERNALS
  63.  
  64.     HISTORY
  65.     29-10-95    digulla automatically created from
  66.                 dos_lib.fd and clib/dos_protos.h
  67.  
  68. *****************************************************************************/
  69. {
  70.     __AROS_FUNC_INIT
  71.     __AROS_BASE_EXT_DECL(struct DosLibrary *,DOSBase)
  72.  
  73.     /* Get pointer to filehandle */
  74.     struct FileHandle *fh=(struct FileHandle *)BADDR(file);
  75.  
  76.     /* Get pointer to process structure */
  77.     struct Process *me=(struct Process *)FindTask(NULL);
  78.  
  79.     /* Get pointer to I/O request. Use stackspace for now. */
  80.     struct IOFileSys io,*iofs=&io;
  81.  
  82.     /* Prepare I/O request. */
  83.     iofs->IOFS.io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  84.     iofs->IOFS.io_Message.mn_ReplyPort     =&me->pr_MsgPort;
  85.     iofs->IOFS.io_Message.mn_Length     =sizeof(struct IOFileSys);
  86.     iofs->IOFS.io_Device =fh->fh_Device;
  87.     iofs->IOFS.io_Unit     =fh->fh_Unit;
  88.     iofs->IOFS.io_Command=FSA_WRITE;
  89.     iofs->IOFS.io_Flags  =0;
  90.     iofs->io_Args[0]=(IPTR)buffer;
  91.     iofs->io_Args[1]=length;
  92.  
  93.     /* Send the request. */
  94.     DoIO(&iofs->IOFS);
  95.  
  96.     /* Set error code and return */
  97.  
  98.     if((me->pr_Result2=iofs->io_DosError))
  99.     return -1;
  100.     else
  101.     return iofs->io_Args[1];
  102.     __AROS_FUNC_EXIT
  103. } /* Write */
  104.